package ar.com.mindset.geometrics.effects {
	import ar.com.mindset.geometrics.MapItem;
	import ar.com.mindset.geometrics.RegionsEffectStrategy;
	import ar.com.mindset.geometrics.effects.*;

	import mx.effects.AnimateProperty;
	import mx.effects.CompositeEffect;
	import mx.effects.Effect;
	import mx.effects.Parallel;

	public class ExplodeEffectStrategy implements RegionsEffectStrategy {

		public function createEffect(regions:Array):Effect {
			var retVal:CompositeEffect=new Parallel();
			for (var i:Number=0; i < regions.length; i++) {
				var region:MapItem=regions[i];
				retVal.addChild(getEffect(region));
			}

			retVal.duration=2000;
			return retVal;
		}

		private function getEffect(target:Object):Effect {
			var retVal:Parallel=new Parallel();
			var movX:AnimateProperty=new AnimateProperty();
			movX.property="x";
			movX.fromValue=target.x;
			if (Math.random() < 0.5) {
				//left
				movX.toValue=-800;
			} else {
				//right
				movX.toValue=3000
			}
			var movY:AnimateProperty=new AnimateProperty();
			movY.property="y";
			movY.fromValue=target.y;
			movY.toValue=Math.random() * 4000 - 2000;

			retVal.addChild(movX);
			retVal.addChild(movY);

			retVal.target=target;
			return retVal;
		}

		public function toString():String {
			return "Explode";
		}

	}
}